package com.mind.system.domain;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.mind.common.annotation.Excel;
import com.mind.common.utils.DateUtils;
import com.mind.common.utils.StringUtils;
import lombok.Data;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Date;
import java.util.List;


/**
 * 单据任务(AjTicketTask)
 *
 * @author makejava
 * @since 2024-09-09 11:26:05
 */
@Data
@TableName("aj_ticket_task")
public class AjTicketTask implements Serializable {
    /**
     * 主键
     */     
    @ExcelIgnore
    private Integer id;
    /**
     * 任务名称
     */     
//    @Excel(name = "任务名称")
    @ExcelProperty("任务名称")
    private String name;
    /**
     * 单据编号
     */     
    @Excel(name = "单据编号")
    @ExcelProperty("单据编号")
    private String ticketId;
    /**
     * 单据类型
     */     
    @Excel(name = "单据类型")
    @ExcelProperty("单据类型")
    private String ticketType;

    /**
     * 业务小类
     */
    @Excel(name = "业务小类")
    @ExcelProperty("业务小类")
    private String businessCate;

    /**
     * 业务大类
     */
    @Excel(name = "业务大类")
    @ExcelProperty("业务大类")
    private String businessMainCate;
    /**
     * 版本
     */     
    @Excel(name = "版本")
    @ExcelProperty("版本")
    private Integer version;
    /**
     * 组织ID
     */     
//    @Excel(name = "组织ID")
    @ExcelProperty("组织ID")
    private String orgId;
    /**
     * 单据信息
     */     
//    @Excel(name = "单据信息")
    @ExcelProperty("单据信息")
    private String info;
    /**
     * 状态(1:待处理,2:处理中,3:成功,4:失败)
     */     
    @Excel(name = "智审状态", readConverterExp = "1=待处理,2=处理中,3=成功,4=失败")
    @ExcelProperty("状态(1:待处理,2:处理中,3:成功,4:失败)")
    private Integer status;



    /**
     * 默认0全量触发, 1 只触发规则检查 2 只触发单据
     */     
//    @Excel(name = "默认0全量触发, 1 只触发规则检查 2 只触发单据", readConverterExp = "0=全量触发,1=只触发规则检查,2=只触发单据")
    @ExcelProperty("默认0全量触发, 1 只触发规则检查 2 只触发单据")
    private Integer triggerType;
    /**
     * 处理结果 1 待处理 2 退回发起人 3通过 4 系统自动完成
     */     
    @Excel(name = "处理结果", readConverterExp = "1=待处理,2=退回发起人,3=手动通过,4=系统自动完成,5=退影像,6=自动通过")
    @ExcelProperty("处理结果 1 待处理 2 退回发起人 3通过 4 系统自动完成")
    private Integer handleResult;
    /**
     * 处理者昵称
     */
    @Excel(name = "处理人")
    @ExcelProperty("处理者昵称")
    private String handleNickname;
    /**
     * 创建时间
     */
    @Excel(name = "推送时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    @ExcelIgnore
    private Date createTime;
    /**
     * 更新时间
     */
    @ExcelIgnore
    private Date updateTime;
    /**
     * 查验完成时间
     */
    @Excel(name = "查验完成时间", width = 30,dateFormat = "yyyy-MM-dd HH:mm:ss")
    @ExcelProperty("查验完成时间")
    private Date completeTime;
    /**
     * 回调时间
     */
    @Excel(name = "处理时间", width = 30,dateFormat = "yyyy-MM-dd HH:mm:ss")
    @ExcelProperty("回调时间")
    @TableField(value = "handel_time")
    private Date handelTime;
    /**
     * 是否转人工 0 否1 是
     */
    @Excel(name = "是否转人工", readConverterExp = "0=否,1=是")
    @ExcelProperty("是否转人工")
    private Integer handleType;
    /**
     * 备注信息
     */

//    @Excel(name = "备注信息")
    @ExcelProperty("备注信息")
    private String remark;
    /**
     * 1 回调正常 2 待回调
     */     
    @Excel(name = "回调状态", readConverterExp = "1=待回调,2=回调正常,3=回调中")
    @ExcelProperty("1 回调正常 2 待回调")
    private Integer callbackStatus;
    /**
     * 回调参数
     */     
//    @Excel(name = "回调参数")
    @ExcelProperty("回调参数")
    private String callbackParams;
    /**
     * 回调次数
     */     
//    @Excel(name = "回调次数")
    @ExcelProperty("回调次数")
    private Integer callbackCount;

    /**
     * 处理用户名
     */     
    @ExcelProperty("处理用户名")
    private String handleUsername;


    @ExcelIgnore
    @TableField(value = "handel_time", condition = "%s >= #{%s}")
    private Date startHandleTime;
    @ExcelIgnore
    @TableField(value = "handel_time", condition = "%s &lt;= #{%s}")
    private Date endHandleTime;

    @ExcelIgnore
    @TableField(value = "create_time", condition = "%s >= #{%s}")
    private String startCreateTime;

    @ExcelIgnore
    @TableField(value = "create_time", condition = "%s &lt;= #{%s}")
    private String endCreateTime;

    private Integer checkResult;

    @ExcelIgnore
    @TableField(exist = false)
    private Boolean isDisplayOnlyHigherVersion;
//
//    public Date getEndHandleTime() {
//        if(StringUtils.isNotNull(endHandleTime)){
//            Date date = DateUtils.addDays(endHandleTime, 1);
//            return DateUtils.addSeconds(date,-1);
//        }else{
//            return null;
//        }
//    }
    /**
     * 错误信息
     */
    @Excel(name = "错误信息")
    @ExcelProperty("错误信息")
    private String errorInfo;
    @TableField(exist = false)
    private String originalField;
    /**
     * 申请开时时间
     */
    @ExcelIgnore
    @TableField(value = "apply_date", condition = "%s >= #{%s}")
    private Date startApplyDate;
    /**
     * 申请结束时间
     */
    @ExcelIgnore
    @TableField(value = "apply_date", condition = "%s &lt;= #{%s}")
    private Date endApplyDate;

    public void setEndApplyDate(Date endApplyDate) {
        if(StringUtils.isNotNull(endApplyDate)) {
            Date date = DateUtils.addDays(endApplyDate, 1);
            this.endApplyDate = DateUtils.addSeconds(date,-1);
        }
    }

    /**
     * 查验开时时间
     */
    @ExcelIgnore
    @TableField(value = "complete_time", condition = "%s >= #{%s}")
    private Date startCompleteDate;
    /**
     * 查验结束时间
     */
    @ExcelIgnore
    @TableField(value = "complete_time", condition = "%s &lt;= #{%s}")
    private Date endCompleteDate;

    public void setEndCompleteDate(Date endApplyDate) {
        if(StringUtils.isNotNull(endApplyDate)) {
            Date date = DateUtils.addDays(endApplyDate, 1);
            this.endCompleteDate = DateUtils.addSeconds(date,-1);
        }
    }

    /**
     * 申请时间
     */
    @ExcelIgnore
    private Date applyDate;
    /**
     * 申请人
     */
    @ExcelIgnore
    private String applyPerson;
    /**
     * 申请部门
     */
    @ExcelIgnore
    private String applyDept;
    /**
     * 申请公司
     */
    @ExcelIgnore
    private String applyComp;

    @ExcelIgnore
    @TableField(exist = false)
    private String businessCates;
    @TableField(exist = false)
    private List<String> businessCateList;

    private List<String> getBusinessCateList() {
        if(StringUtils.isEmpty(businessCates)){
            return null;
        }else{
            return Arrays.asList(businessCates.split(","));
        }
    }

    /**
     * 规则版本
     */
    @TableField(exist = false)
    private String ruleVersion;
    /**
     * 规则集
     */
    @TableField(exist = false)
    private String ruleset;


    private Long passCount;

    private Long totalCount;

    /**
     * 规则类型
     */
    @TableField(exist = false)
    private String ruleType;
    /**
     * 规则名称
     */
    @TableField(exist = false)
    private String ruleDetailName;


}

